//app.js

var http = require("./utils/httpUtils")
App({
  globalData: {
    SERVER_IP   : "https://www.hxzbi.com:4000",
    WX_SERVER   : "https://www.hxzbi.com:8082/pay-0.0.1-SNAPSHOT",
    // SERVER_IP   : "http://www.hxzbi.com:3200",
    // WX_SERVER   : "http://47.94.231.242:8848/pay-0.0.1-SNAPSHOT",
  },
  onLaunch: function () {
    // 获取用户基础资料和code
    var that = this;
    var userInfo = {};
    wx.login({
      success(loginRes) {
        // 获取code
        console.log("获取code",loginRes)
        userInfo.code = loginRes.code

        // wx.getUserInfo({
          // success: userInfoRes => {
            //获取用户信息
            // console.log("获取用户信息",userInfoRes)
            // userInfo.nickname = userInfoRes.userInfo.nickName
            // userInfo.headerurl = userInfoRes.userInfo.avatarUrl
            userInfo.nickname = "游客"
            userInfo.headerurl = "https://www.baidu.com/img/flexible/logo/pc/result.png"

            // 获取登录信息
            var urls = that.globalData.WX_SERVER + '/app/wx/microAppLogin'
            http.P(urls, userInfo, (res) => {
              console.log("获取登录信息",res.data)

              // 存储登录信息
              wx.setStorage({
                key: "userInfo",
                data: res.data
              })

              // 查询登录信息
              console.log(wx.getStorageSync('userInfo'))
            }, (err) => {
              console.log("获取登录信息失败")
              console.log(err)
            })

          // }
        // })

      }
    })
  }
})